<template>
  <div class="fillcontain">
    <div class="table_container">
      <el-table
        v-loading="tableloading"
        :data="tableData"
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column
          property="dateTime"
          label="时间"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="newUsers"
          label="新增用户"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="totalUsers"
          label="注册用户"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="newEquipments"
          label="新增绑定设备"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="totalEquipments"
          label="绑定设备"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="newTests"
          label="新增检测次数"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="totalTests"
          label="检测次数"
          align="center"
        >
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import headTop from "../components/headTop";
import { fetchHomeChart } from "@/api/getData";
import { ip1Conf } from "@/config/env";
import { formatDate, formatDateTime } from "@/util/common";
export default {
  data() {
    return {
      tableData: [],
      limit: 20,
      currentPage: 1
    };
  },
  components: {
    headTop
  },
  created() {
    this.getHomeChartDataList();
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      if (this.searchInpt !== "") {
        const page = "1";
        this.searchUser(page);
      } else {
        this.getUsers();
      }
    },
    async getHomeChartDataList() {
      this.tableloading = true;
      const homeChartDataListData = await fetchHomeChart();
      this.tableData = [];
      this.tableloading = false;
      homeChartDataListData.data.forEach(item => {
        const tableData = {};
        tableData.dateTime = item.dateTime;
        tableData.newEquipments = item.newEquipments;
        tableData.newTests = item.newTests;
        tableData.newUsers = item.newUsers;
        tableData.totalEquipments = item.totalEquipments;
        tableData.totalTests = item.totalTests;
        tableData.totalUsers = item.totalUsers;
        this.tableData.push(tableData);
      });
    }
  }
};
</script>

<style lang="less">
@import "../style/mixin";
.search-box {
  padding: 20px 0;
}
.search-span {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px;
  box-sizing: border-box;
}
</style>
